package com.jlnx.controller.bank;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jlnx.dao.ChainEnterpriseDaoImpl;
import com.jlnx.dao.CoreEnterpriseDaoImpl;
import com.jlnx.dao.EnterpriseDaoImpl;
import com.jlnx.dao.FinanceReqDaoImpl;
import com.jlnx.pojo.ChainEnterprise;
import com.jlnx.pojo.CoreEnterprise;
import com.jlnx.pojo.Enterprise;
import com.jlnx.pojo.FinanceReq;

/*
 * 同意准入
 */
@WebServlet("/AgreeInController")
public class AgreeInController extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//获取请求信息
		response.setContentType("application/json;charset=UTF-8;text/html");
		//设置请求编码模式
    	request.setCharacterEncoding("utf-8");
    	
    	String entNo = request.getParameter("entNo");
    	int role = Integer.parseInt(request.getParameter("role"));
    	
		 CoreEnterpriseDaoImpl coredao = new CoreEnterpriseDaoImpl();
		 ChainEnterpriseDaoImpl chaindao = new ChainEnterpriseDaoImpl();
				
		 //获取session对象
		 HttpSession hs=request.getSession();
		 //获取登录账号
		 String bankentNo = ((Enterprise)hs.getAttribute("enterprise")).getEntNo();
		 System.out.println( bankentNo + ":同意" + entNo + "准入");

		 if(role == 1) {//核心企业准入
			 if(coredao.changeInstatus(entNo, 2) < 0) {
				 request.getRequestDispatcher("/main/inEnterpriseSearch.jsp").forward(request, response);
			 }else {
				 request.getRequestDispatcher("/getInReqEnterpriseController").forward(request, response);
			 }

		 }else if(role == 3){//链条企业准入
			 if(chaindao.changeInstatus(entNo, 2) < 0) {
				 request.getRequestDispatcher("/main/inEnterpriseSearch.jsp").forward(request, response);
			 }else {
				 request.getRequestDispatcher("/getInReqEnterpriseController").forward(request, response);
			 }
		 }

		//TODO  修改剩余额度
		//发起还款，修改还款状态
//		if(dao.returnById(reqId)<0) {
//			request.getRequestDispatcher("/main/returnReq.jsp").forward(request, response);
//		}else {
//			request.getRequestDispatcher("/ReturnStatusSearchController").forward(request, response);
//		}
				
	}

}
